import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Test13 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<String> nameList = new ArrayList<String>();
        List<String> valueList=new ArrayList<String>();
        for (int i = 1; i <= n; i++) {
            String name = sc.next();
            if(nameList.contains(name)){
                int index = nameList.indexOf(name);
                String value = valueList.get(index);
                valueList.remove(index);
                valueList.add(index,value+","+i);
            }else {
                nameList.add(name);
                valueList.add(String.valueOf(i));
            }

        }
        for(int j = 0; j < nameList.size(); j++){
            System.out.print(nameList.get(j)+"("+valueList.get(j)+")");
        }

    }
}
